home *** CD-ROM | disk | FTP | other *** search
/ DS-CD ROM 2 1993 August / DS CD-ROM 2.Ausgabe (August 1993).iso / programm / ds0257 / demo.exe / MEMORY.DEM < prev    next >
Text File  |  1992-02-16  |  12KB  |  412 lines

  1. ; ----------------------------
  2. ; MEMORY.DEM   - Demoprogramm für die Routinen aus MEMORY.LIB
  3. ;                (für den A86)
  4. ;
  5. ;                (c) Bernd Schemmer 1992
  6. ;                Letzter Update: 15.02.1992
  7. ;
  8. ; Übersetzen:
  9. ;  A86 MEMORY.DEM DEMOS.INC TO MEMORY.COM
  10. ;
  11. ; Hinweis: Die Environment-Variable 'A86' muß den Dateinamen 'MACROS.MAC'
  12. ;          enthalten und die .LIB-Dateien müssen über die Datei A86.LIB
  13. ;          erreichbar sein.
  14. ;
  15. ; ---------------------------
  16.          jmp start
  17.  
  18. ; ----------------------------
  19.  
  20. logo db 'MEMORY.DEM - Demo für die Routinen aus MEMORY.LIB',CR,LF
  21.      db '-------------------------------------------------',CR,LF
  22.      db CR,LF
  23. GETLENGTH Logo
  24.  
  25. MakeMsg MarkBlock,  'Markiere unseren Speicherblock mittels "SetBlockName" ...'
  26. MakeMsg OwnBlock1,  'Daten des Speicherblocks von MEMORY.COM:'
  27. MakeMsg ShrinkMsg,  'Verkleinere den Speicherblock von MEMORY.COM mittels "SetBlockSize" ...'
  28. MakeMsg OwnBlock2,  'Daten des Speicherblocks von MEMORY.COM nach der Verkleinerung:'
  29. MakeMsg AllocMsg,   'Belege einen Speicherbereich mit 384 K mittels "GetMemoryBlock"  ...'
  30. MakeMsg Alloc0Msg,  '384 K kriegen wir nicht, nehmen wir, was wir kriegen können ...'
  31. MakeMsg Alloc1Msg,  'Daten des neuen Speicherblocks:'
  32. MakeMsg Alloc2Msg,  'Ermittle die Daten des neuen Blocks über "GetBlockSize" ... '
  33. MakeMsg FreeMsg1,   'Gebe den Block wieder frei mittels "FreeMemoryBlock" ...'
  34. MakeMsg SearchMsg,  'Suche unseren Speicherblock mittels "SearchMemoryBlock" ...'
  35. MakeMsg FoundMsg,   'Unseren Speicherblock gefunden!'
  36. MakeMsg NotFoundMsg,'Nanu, unseren Speicherblock nicht gefunden!'
  37.  
  38. OurName  db 8,'_MEMORY_'      ; Name für unseren Speicherblock als String
  39.  
  40. ; ----------------------------
  41. start:
  42.          call ShowLogo        ; Logo ausgeben und Speicherblock verkleinern
  43.  
  44.          Write_String MarkBlock
  45.  
  46.                               ; Unseren Speicherblock markieren
  47.          mov si,offset OurName
  48.          call SetBlockName
  49.          call CheckMemoryError
  50.          IF c jmp ErrorEnde
  51.  
  52.          Write_String OwnBlock1
  53.          call ShowMemoryData
  54.  
  55.          Write_String ShrinkMsg
  56.                               ; akt. Speicherblock verkleinern
  57.          mov bx,1000h         ; 1 Segment
  58.          call SetBlockSize
  59.          call CheckMemoryError
  60.          if c jmp ErrorEnde
  61.  
  62.          Write_String OwnBlock2
  63.          call ShowMemoryData
  64.  
  65.          Write_String AllocMsg
  66.          mov bx,06000h
  67.          call GetMemoryBlock
  68.          jnc >l1              ; okay
  69.  
  70.                               ; Fehler
  71.          cmp ax,08h
  72.          jne >l2
  73.  
  74.          push bx
  75.          Write_String Alloc0Msg
  76.          pop bx
  77.                               ; 1 Segment nicht verfügbar, nehmen wir
  78.                               ; was wir kriegen können
  79.          call GetMemoryBlock
  80.          jnc >l1
  81. l2:
  82.          stc                  ; Fehler
  83.          call CheckMemoryError
  84.          IF c jmp ErrorEnde
  85. l1:
  86.          mov es,ax
  87.  
  88.          Write_String Alloc1Msg
  89.          call ShowMemoryData
  90.  
  91.          call GetBlockSize
  92.          call CheckMemoryError
  93.          IF c jmp ErrorEnde
  94.  
  95.          call ShowMemoryData1
  96.  
  97.          Write_String FreeMsg1
  98.          call FreeMemoryBlock
  99.          call CheckMemoryError
  100.          IF c jmp ErrorEnde
  101.  
  102.          call ShowMemoryAllocationStrat
  103.          IF c jmp ErrorEnde
  104.  
  105.          Write_String SearchMsg
  106.  
  107.          mov si,offset OurName
  108.          call SearchMemoryBlock
  109.          jc >l1
  110.          Write_String FoundMsg
  111.          jmp >l2
  112. l1:
  113.          Write_String NotFoundMsg
  114. l2:
  115.          mov al,0
  116.          jmp SHORT Ende
  117.  
  118. ErrorEnde:
  119.          call ShowCR_LF
  120.          call OutputMsg
  121.  
  122.          mov al,0FFh
  123.  
  124. Ende:
  125.          EndProcess
  126.          ret
  127.  
  128. ; ----------------------------
  129. ; ShowMemoryAllocationStrat
  130. ;
  131. ; Funktion: Ausgabe der akt. Speicherbelegungs-Strategie
  132. ;
  133. ;
  134. MakeMsg  StratMsg1,  'Ermittle die aktuelle Belegungsstrategie mittels "GetMemoryStrategie" ...'
  135. MakeMsg1 StratMsg2,  'Aktuelle Belegungsstrategie ist: '
  136. MakeMsg  StratMsg3,  'First Fit'
  137. MakeMsg  StratMsg4,  'Best Fit'
  138. MakeMsg  StratMsg5,  'Last Fit'
  139. MakeMsg1 StratMsg6,  'UMB only AND '
  140. MakeMsg1 StratMsg7,  'UMB first AND '
  141.  
  142. ShowMemoryAllocationStrat:
  143.          Write_String StratMsg1
  144.          Write_String StratMsg2
  145.  
  146.          call GetMemoryStrategy
  147.          call CheckMemoryError
  148.          IF c ret
  149.  
  150.          push ax
  151.          mov ah,030h
  152.          int 021h             ; DOS-Version berücksichtigen
  153.          cmp al,05
  154.          pop ax
  155.  
  156.          jb >l2
  157.                               ; ab DOS 5 UMB-Bits berücksichtigen
  158.          test al,040h
  159.          jz >l1
  160.          push ax
  161.          Write_String StratMsg6
  162.          pop ax
  163. l1:
  164.          test al,080h
  165.          jz >l2
  166.          push ax
  167.          Write_String StratMsg7
  168.          pop ax
  169. l2:
  170.          and al,011xB         ; nur die Bits 0 und 1 sind von Bedeutung
  171.  
  172.          or al,al
  173.          jne >l1
  174.          Write_String StratMsg3
  175.          jmp >l2
  176. l1:
  177.          dec al
  178.          jne >l1
  179.          Write_String StratMsg4
  180.          jmp >l2
  181. l1:
  182.          Write_String StratMsg5
  183. l2:
  184.          call ShowCR_LF
  185.          clc
  186.          ret
  187.  
  188. ; ----------------------------
  189. ; ShowMemoryData1
  190. ;
  191. ; Funktion: Ausgabe der Daten eines Speicherblocks
  192. ;
  193. ; Eingabe:  BX = Größe des Blocks in Paragraphen
  194. ;           AX = Besitzer des Speicherblocks
  195. ;
  196. ; Ausgabe:  -
  197. ;
  198. MemoryBlockMsg1 db
  199.                 db 'Länge: '
  200. M20             db 'xxxxh Paragraphen, '
  201.                 db 'Besitzer: '
  202. M40             db 'xxxxh '
  203.                 db CR,LF
  204.                 db CR,LF
  205. GETLENGTH MemoryBlockMsg1
  206.  
  207. ShowMemoryData1:
  208.          push es
  209.  
  210.          mov es,cs
  211.  
  212.          push ax
  213.          mov ax,bx            ; AX = Größe
  214.          mov di,offset M20
  215.          call Konvert_AX_To_Hexstring
  216.          pop ax
  217.                               ; AX = Besitzer
  218.  
  219.          cmp ax,0
  220.          jne >l1
  221.                               ; Block ist frei
  222.          mov W es:M40,'rf'
  223.          mov w es:M40+1,'ie'
  224.          mov b es:M40+3,' '
  225.          jmp >l2
  226. l1:
  227.          cmp ax,08
  228.          jne >l1
  229.                               ; Block gehört DOS
  230.          mov W es:M40,'OD'
  231.          mov w es:M40+1,'S '
  232.          mov b es:M40+3,' '
  233.          jmp >l2
  234.  
  235. l1:
  236.                               ; AX = PSP des Besitzers
  237.          mov di,offset M40
  238.          call Konvert_AX_To_Hexstring
  239.          mov al,'h'
  240.          stosb
  241. l2:
  242.          pop es
  243.          Write_String MemoryBlockMsg1
  244.          ret
  245.  
  246. ; ----------------------------
  247. ; ShowMemoryData
  248. ;
  249. ; Funktion: Ausgabe der Daten eines Speicherblocks
  250. ;
  251. ; Eingabe:  ES = Segment des Speicherblocks
  252. ;
  253. ; Ausgabe:  -
  254. ;
  255. MemoryBlockMsg db 'Adresse: '
  256. M1             db 'xxxxh, Länge: '
  257. M2             db 'xxxxh Paragraphen, '
  258.                db 'Besitzer: '
  259. M4             db 'xxxxh, Name: '
  260. M5             db 'xxxxxxxx'
  261.                db CR,LF
  262.                db CR,LF
  263. GETLENGTH MemoryBlockMsg
  264.  
  265. ShowMemoryData:
  266.          push ds,es
  267.  
  268.          mov ax,es
  269.          dec ax
  270.          mov ds,ax            ; DS = MCB des Speicherblocks
  271.  
  272.          mov ax,es            ; AX = Segment
  273.  
  274.          push cs
  275.          pop es               ; ES = CS
  276.  
  277.          mov di,offset M1
  278.          call Konvert_AX_To_HexString
  279.  
  280.          mov ax,[03]          ; AX = Länge in Paragraphen
  281.          mov di,offset M2
  282.          call Konvert_AX_TO_Hexstring
  283.  
  284.          mov ax,[01]          ; AX = Besitzer
  285.          cmp ax,0
  286.          jne >l1
  287.                               ; Block ist frei
  288.          mov W es:M4,'rf'
  289.          mov w es:M4+1,'ie'
  290.          mov b es:M4+3,' '
  291.          jmp >l2
  292. l1:
  293.          cmp ax,08
  294.          jne >l1
  295.                               ; Block gehört DOS
  296.          mov W es:M4,'OD'
  297.          mov w es:M4+1,'S '
  298.          mov b es:M4+3,' '
  299.          jmp >l2
  300.  
  301. l1:
  302.                               ; AX = PSP des Besitzers
  303.          mov di,offset M4
  304.          call Konvert_AX_To_Hexstring
  305.          mov al,'h'
  306.          stosb
  307. l2:
  308.                               ; Name erstmal löschen
  309.          mov di,offset M5
  310.          mov ax,'--'
  311.          stosw
  312.          stosw
  313.          stosw
  314.          stosw
  315.  
  316.          pop es               ; ES = Segment
  317.          push es
  318.  
  319.          mov ds,cs
  320.          mov si,offset M5-1
  321.  
  322.          mov al,[si]
  323.          push ax
  324.          call GetOwnerName
  325.          pop ax
  326.          mov [si],al
  327.  
  328.          pop es,ds
  329.          Write_String MemoryBlockMsg
  330.          ret
  331.  
  332. ; ----------------------------
  333. ; CheckMemoryError
  334. ;
  335. ; Funktion: Ermitteln der zu einer Fehlernummer
  336. ;           gehörenden Fehlermeldung
  337. ;
  338. ; Eingabe:  AX = Fehlercode der Routine
  339. ;           CF = CF der Routine
  340. ;
  341. ; Ausgabe:  CF = 0 ->> kein Fehler
  342. ;                      kein Register verändert
  343. ;           CF = 1 ->> Fehler
  344. ;                      DX = Offset der Fehlermeldung
  345. ;                      CX = Länge der Fehlermeldung
  346. ;                      AX unverändert
  347. ;
  348.  
  349. ; Fehlermeldungen
  350. ; ---------------
  351. MErrMsg0 db '*** Fehler in der MCB-Kette'
  352. MErrMsg1 db '*** Zuwenig freier Speicher'
  353. MErrMSg2 db '*** Falsche Speicherblockadresse angegeben (DOS-Fehler 9)'
  354. MErrMsg3 db '*** Falsche Blockadresse angegeben'
  355. MErrMsg4 db '*** Falsche Blockgröße angegeben'
  356. MErrMsg5 db '*** Der Block ist frei'
  357. MErrMsg6 db '*** Der Block gehört DOS'
  358. MErrMsg7 db '*** Der Block ist kein Hauptblock'
  359. MErrMsg8 db '*** Falscher Name für den Block angegeben'
  360. MErrMsg9 db '*** Block nicht gefunden'
  361. MErrMsgU db '*** Unbekannter Fehlercode'
  362. MErrmsgL db ' '
  363.  
  364. ; Tabelle der Fehlernummern und Fehlermeldungen
  365. ; ---------------------------------------------
  366.  
  367.                      ; Fehlernummern         Offset der Fehlermeldung
  368.                      ; -----------------------------------------------
  369. MErrMsgTable        dw 07                  , Offset MErrMsg0
  370.                     dw 08                  , Offset MErrMsg1
  371.                     dw 09                  , Offset MErrMsg2
  372.                     dw MemoryBlockError    , Offset MErrMsg3
  373.                     dw InvalidBlockLength  , Offset MErrMsg4
  374.                     dw BlockIsFree         , Offset MErrMsg5
  375.                     dw BlockBelongsToDOS   , Offset MErrMsg6
  376.                     dw BlockIsNoMainBlock  , Offset MErrMsg7
  377.                     dw InvalidBlockName    , Offset MErrMsg8
  378.                     dw BlockNotFound       , Offset MErrMsg9
  379.                               ; Eintrag für unbekannte Fehlercodes
  380. MErrUnknown         dw 0                   , Offset MErrMsgU
  381.                               ; Eintrag für die Ermittlung der Länge
  382.                               ; der letzten Fehlermeldung
  383.                     dw 0                   , Offset MErrMsgL
  384.  
  385. CheckMemoryError:
  386.          jnc ret              ; CF = 0 ->> kein Fehler aufgetreten
  387.  
  388.          push si,ds,ax        ; CF = 1 ->> Fehler aufgetreten,
  389.                               ;            Offset der Fehlermeldung ermitteln
  390.          mov ds,cs            ; DS = CS
  391.          mov si,offset MErrMsgTable
  392.                               ; DS:SI -> Fehlertabelle
  393.  
  394.                               ; Eintrag für unbekannte Fehlercodes korrigieren
  395.          mov MErrUnknown,ax
  396.  
  397.          mov dx,ax            ; Fehlernummer nach DX
  398. l0:
  399.          lodsw
  400.          cmp ax,dx
  401.          lodsw
  402.          jne l0
  403.  
  404.          mov dx,ax            ; DX = Offset der Fehlermeldung
  405.          mov cx,[si+2]        ; CX = Offset der nächsten Fehlermeldung
  406.          sub cx,dx            ; CX = Länge der Fehlermeldung
  407.          stc
  408.  
  409.          pop ax,ds,si
  410.          ret
  411.  
  412.